<?php
class CommonUtil {
	// 静态数据，不可修改
	static $httpMethod = "PUT";
	
	// 判断水印图片是否为png格式，以及大小是否超过5M
	public static function isLegalPicture($filePath) {
		$png = array (
				"89504E47",
				"png" 
		);
		$file = fopen ( $filePath, "rb" );
		// 读取15个字节就够了
		$bin = fread ( $file, '15' );
		/*
		 * $blen = strlen(pack("H*", $png[0]));//获取png，16进制长度
		 * $tbin = substr($bin, 0, intval($blen)); ///需要比较文件头长度
		 */
		if (stristr ( $bin, $png [1] ) == "") {
			return false;
		}
		$fileSize = filesize ( $filePath );
		if ($fileSize > (1024 * 1024 * 5)) {
			return false;
		}
		return true;
	}
	
	public static function upload($presignedUrl, $file) {
		// 调用restful服务
		$http = new \Http ();
		$headers = array ();
		$headers [] = "Content-Type:multipart/form-data";
		$httpOptions = array (
				CURLOPT_HTTPHEADER => $headers,
				CURLOPT_POSTFIELDS => $file   // 设置请求体
		);
		$result = $http->doPut ( $presignedUrl, null, $httpOptions );
		return $result;
	}
}
?>